package cn.site.jupitermouse.lineage.graph.domain.model;

import java.util.HashMap;
import java.util.Map;

import cn.site.jupitermouse.lineage.graph.contants.NeoConstant;
import lombok.Getter;
import lombok.Setter;
import org.neo4j.ogm.annotation.Properties;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * Unified abstraction of graph relationships and node entities
 * </p>
 *
 * @author JupiterMouse 2020/09/27
 * @since 1.0
 */
@Setter
@Getter
public abstract class BaseEntity {
    /**
     * Figure real ID，Generated by neo4j engine，Can't be modified
     */
    private Long id;

    /**
     * Node extra value, starting with ext prefix
     */
    @Properties(prefix = NeoConstant.ENTITY_EXTRA_PREFIX)
    private Map<String, String> extra;

    public Map<String, String> getExtra() {
        if (CollectionUtils.isEmpty(extra)) {
            synchronized (this) {
                if (CollectionUtils.isEmpty(extra)) {
                    this.extra = new HashMap<>(16);
                }
            }
        }
        return this.extra;
    }

}
